package com.example.nfc.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.nfc.R;
import com.example.nfc.server.response.Admin;

import java.util.List;

/**
 * 提示框
 */
public class SelectDialog extends BaseDialog{

    public String data;
    private LayoutInflater inflater;
    private LinearLayout list ;
    public SelectDialog(Context context) {
        super(context, R.layout.dialog_select);
        setTitle("请选择所属经销商");
        hideSubmit();
        setCancelTxt("取消");
        hideJihuo();
        list = view.findViewById(R.id.list);
        inflater = LayoutInflater.from(context);

    }
    public void setData(List<Admin> admins){
        list.removeAllViews();
        for(Admin a:admins){
            View view = inflater.inflate(R.layout.dialog_select_item,null,false);
            view.setTag(R.id.tag_1,a.getUser_id());
            view.setTag(R.id.tag_2,a.getUser_name());
            TextView textView = view.findViewById(R.id.title);
            textView.setText(a.getUser_name());
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String uid = (String)v.getTag(R.id.tag_1);
                    String name = (String)v.getTag(R.id.tag_2);
                    if(onSelect!=null){
                        onSelect.select(uid,name);
                    }
                }
            });
            list.addView(view);
        }
    }


    @Override
    public void onClose() {

    }

    @Override
    public boolean onCancel() {
        return true;
    }

    @Override
    public boolean onSubmit() {
        return true;
    }

    private OnSelect onSelect;

    public OnSelect getOnSelect() {
        return onSelect;
    }

    public void setOnSelect(OnSelect onSelect) {
        this.onSelect = onSelect;
    }

    public interface OnSelect{
        void select(String uid,String name);
    }

}
